﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Krist_em_up.Components;
using Microsoft.Xna.Framework;
using Map_Editor.Effects;

namespace Map_Editor
{
    public class Button
    {
        public Texture2D sprite, cursor;

        protected Souris s;
        protected ClickEffect effect;
        protected Sidebar sidebar;
        protected Rectangle rectangle;
        public Button(ClickEffect e, Texture2D text, Rectangle rect, Sidebar sidebar)
        {
            s = new Souris(sidebar.Game);
            sprite = text;
            rectangle = rect;
            effect = e;
            this.sidebar = sidebar;
        }

        public void Update(GameTime gametime)
        {
            s.Update(gametime);
            Rectangle r = new Rectangle((int)s.getCoord().X, (int)s.getCoord().Y, 1, 1);
            Rectangle realRect = new Rectangle(rectangle.X + sidebar.Game.GraphicsDevice.Viewport.X, rectangle.Y, rectangle.Width, rectangle.Height); 
            
            if (realRect.Contains(r) && s.LeftClicked())
            {
                sidebar.SetEffect(effect);
            }
        }

        public void Draw(SpriteBatch spritebatch)
        {
            spritebatch.Draw(sprite, rectangle, Color.White);
        }

    }
}
